﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// DirectionalBlurEffect Effect
    /// </summary>
    public class DirectionalBlurEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(DirectionalBlurEffect), 0);
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(DirectionalBlurEffect), new UIPropertyMetadata(0.0, ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty BlurAmountProperty = DependencyProperty.Register("BlurAmount", typeof(double), typeof(DirectionalBlurEffect), new UIPropertyMetadata(0.0, ShaderEffect.PixelShaderConstantCallback(1)));

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(DirectionalBlurEffect.InputProperty));
            }
            set
            {
                this.SetValue(DirectionalBlurEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Angle du Shader
        /// </summary>
        public double Angle
        {
            get
            {
                return ((double)this.GetValue(DirectionalBlurEffect.AngleProperty));
            }
            set
            {
                this.SetValue(DirectionalBlurEffect.AngleProperty, ((value % 360) + 360) % 360);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété BlurAmount du Shader
        /// </summary>
        public double BlurAmount
        {
            get
            {
                return ((double)this.GetValue(DirectionalBlurEffect.BlurAmountProperty));
            }
            set
            {
                this.SetValue(DirectionalBlurEffect.BlurAmountProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur statique
        /// </summary>
        static DirectionalBlurEffect()
        {
            DirectionalBlurEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/DirectionalBlur.ps");
        }

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        public DirectionalBlurEffect()
        {
            this.PixelShader = DirectionalBlurEffect._PixelShader;

            this.UpdateShaderValue(DirectionalBlurEffect.InputProperty);
            this.UpdateShaderValue(DirectionalBlurEffect.AngleProperty);
            this.UpdateShaderValue(DirectionalBlurEffect.BlurAmountProperty);
        }

        #endregion
    }
}
